package com.werdior.log.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.werdior.common.entity.ReturnDTO;
import com.werdior.common.util.R;
import com.werdior.log.entity.SysLog;
import com.werdior.log.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import com.xiaoleilu.hutool.convert.Convert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author werdior
 * @since 2017-12-23
 */
@Controller
@RequestMapping("/log/sysLog")
public class SysLogController {
    @Autowired
    private ISysLogService sysLogService;
    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        Map<String,Object> map=new HashMap<>();
        EntityWrapper<SysLog> wrapper = new EntityWrapper<>();
        if (params.containsKey("key")){
            wrapper.like("username",params.get("key").toString()).or().like("operation",params.get("key").toString());
        }
        wrapper.orderBy("create_date", false);
        Page<SysLog> logPage=sysLogService.selectPage(new Page<>(Convert.toInt(params.get("page")),Convert.toInt(params.get("limit"))),wrapper);
        map.put("count",sysLogService.selectCount(wrapper));
        map.put("data", logPage.getRecords());
        return R.ok(map);
    }
}
